/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef VAR_H
#define VAR_H

#include <Windows.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <cantopenfile.h>
#include "varnode.h"
#include "vartype.h"
#include "varlabel.h"

using namespace std;

/////////////////////////////////////////////////////////////////
// Var: Variable handler
/////////////////////////////////////////////////////////////////
class Var
{
public: // Construction
	Var()
	{
		Init();
	}

	Var(const Var& rhs)
	{
		Init();
		Copy(rhs);
	}

public: // Methods
	void Set(const VarNode& rhs); // Declares a variable
	void SetType(const VarNode& rhs); // Declares a type
	void EndType(); // End of a type

	VarNode *Get(const wchar_t *label); // Gets a variable by label
	VarNode *Get(TYPE_WORD offset); // Gets variable by offset

public: // Methods
	Var& Append(const Var& rhs); // Appends
	Var& Append(const VarNode& rhs); 

public: // Operators
	Var& operator = (const Var& rhs)
	{
		Copy(rhs);
		return *this;
	}

private: // Attributes
	vector<VarNode> _offset_globals; // Global variables
	vector<VarNode> _offset_locals; // Local variables

	vector<VarLabel> _label_globals; // Pointers to global variables
	vector<VarLabel> _label_locals; // Pointers to local variables

	TYPE_WORD _sp; // Stack pointer
	TYPE_WORD _bp; // Base pointer

	bool _is_type; // True if defining a type (like a structure)
};
#endif-
